import { getDeliveryInfo, getDriverList, getChuFillList,getFillList } from '@/gql/keyeRehydrator';
import { toPublish } from '@mqtt';
import { defineStore } from 'pinia';
import { getDriverID } from './driverID';
import { showLoading } from '@/utils/prompt';
export const fillingStation = defineStore('keyeRehydrator', {
  state: () => ({
    id: uni.getStorageSync('delivery_id')?uni.getStorageSync('delivery_id'):1,
    name: '',
    price: '',
    address: '',
    money: '',
    getDriverList: [],
    getChuFillList:[],
    getFillList:[],
  }),
  getters: {},
  actions: {
    // 加注站信息
    getDeliveryIn(handler = () => { }) {
      const delivery_id=this.id
      showLoading('加载中');
      const payload = {
        query: getDeliveryInfo,
        variables: { delivery_id,driver_id:getDriverID() },
      };
      toPublish(
        'ql/delivery_customersQL/getDeliveryInfo',
        payload,
        (obj : any) => {
          const userInfo = obj.data;
          const { getDeliveryInfo } = userInfo;
          this.id = getDeliveryInfo.id
          this.name = getDeliveryInfo.name
          this.price = getDeliveryInfo.price
          this.address = getDeliveryInfo.address
          this.money = getDeliveryInfo.money
          uni.setStorageSync('delivery_id', getDeliveryInfo.id)
          handler();
        },
      );
    },
    //补液员列表
    filler() {
      showLoading('加载中');
      const payload = {
        query: getDriverList,
        variables: { delivery_id: uni.getStorageSync('delivery_id')},
      };
      toPublish(
        'ql/delivery_customersQL/getDriverList',
        payload,
        (obj : any) => {
          const { getDriverList } = obj.data;
          this.getDriverList = getDriverList
        },
      );
    },
    //受液机列表
    Receiver() {
      showLoading('加载中');
      const payload = {
        query: getFillList,
        variables: { delivery_id: uni.getStorageSync('delivery_id') },
      };
      toPublish('ql/delivery_customersQL/getFillList',payload,
        (obj : any) => {
          const { getFillList } = obj.data;
          this.getFillList=getFillList
        },
      );
    },
    //出液机列表
    machine(){
      showLoading('加载中');
      const payload = {
        query: getChuFillList,
        variables: { delivery_id: uni.getStorageSync('delivery_id') },
      };
      toPublish('ql/delivery/getChuFillList',payload,
        (obj : any) => {
          const { getChuFillList } = obj.data;
          this.getChuFillList=getChuFillList
        },
      );
    }
  },
});